package com.chisheng.controller;

import com.chisheng.common.CResponse;
import com.chisheng.pojo.SecureProblem;
import com.chisheng.service.SecureExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/api/secure")
public class SecureExamController {

    /**
     * SecureExamService
     */
    private SecureExamService ses;

    /**
     * 精确检索
     *
     * @param problem SecureProblem
     * @return CResponse
     */
    @PostMapping(value = "/search", produces = "application/json")
    public CResponse accurateSearch(@RequestBody SecureProblem problem) {
        List<Integer> solution = ses.accurateSearch(problem.getSubject());

        // 无结果
        if (solution == null || solution.size() == 0) {
            return new CResponse(false, "未收录该题", List.of());
        }

        return new CResponse(true, "查询成功", solution);
    }

    @Autowired
    public void setSes(SecureExamService ses) {
        this.ses = ses;
    }

}
